<template>
  <div>`
    <div class="header-abs" v-show="!showHeader">
      <router-link to="/" tag="div">
        <div class="iconfont header-abs-back">&#xe624;</div>
      </router-link>
    </div>
    <div class="header" v-show="showHeader" :style="opacityStyle">
      景点详情
      <router-link to="/" tag="div">
        <div class="iconfont header-back">&#xe624;</div>
      </router-link>
    </div>
  </div>
</template>
<script>
  export default {
    name: 'Header',
    data() {
      return {
        showHeader: false,
        opacityStyle: {
          opacity: 0
        }
      }
    },
    methods: {
      handleScroll() {
        const top = document.documentElement.scrollTop;
        console.log(top);
        if (top > 60) {
          let opacity = top / 140;
          opacity = opacity > 1 ? 1 : opacity;
          this.opacityStyle={opacity};
          this.showHeader = true;
        } else {
          this.showHeader = false;
        }
      }
    },
    activated() {
      window.addEventListener('scroll', this.handleScroll)
      console.log("添加监听")
    },
    deactivated(){
      window.removeEventListener('scroll', this.handleScroll)
      console.log("移除监听")
    }
  }
</script>
<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .header-abs
    position fixed
    left .2rem
    top .2rem
    width .8rem
    height .8rem
    border-radius .4rem
    background rgba(0, 0, 0, 0.8)
    color white
    line-height .8rem
    .header-abs-back
      text-align center
      font-size .32rem
  .header
    z-index 2
    position fixed
    left 0
    top 0
    right 0
    height $headerHeight
    line-height $headerHeight
    background $bgColor
    color #fff
    text-align center
    font-size .32rem
    .header-back
      position absolute
      left 0
      top 0
      width .64rem
      text-align center
      font-size .4rem
      color #ffffff
</style>
